

if(request.method!=='POST'){

	response.forward("/login/login.jst",request,response);
	response.end();

}else{

	var username=request.parameters["username"];
	var password=request.parameters["password"];

	if(typeof username=== 'undefined' || typeof password === 'undefined' ){
		response.forward("/login/login.jst",request,response);
		response.end();
		
	}else{
	
	var authController=request.require("./authController");
	authController.TryLogin(username,password,response,cb);
	}
}

function cb(user,response){

	var loggedIn=false;	
	if(typeof user!=='undefined'){
	
		 if (user["username"] == username && user["password"] == password) {
        loggedIn= true;
    }	
	}

	if(!loggedIn){
	
		var output = {redirect: undefined,msg:"Wrong username or password."};
	
		response.headers["Content-Type"]="application/json";	
		response.headers["Access-Control-Allow-Origin"]="*";
		response.body="";
		response.body+=JSON.stringify(output);
		response.end();
	}else{
	
		
		var session=request.getSession();
		session.LoggedIn=true;
		session.user={
			username:user["username"],
			name:user["name"],
			picture:user["picture"]
				
		};


		var output = {redirect: "/home",msg:undefined};
	
		response.headers["Content-Type"]="application/json";
		response.headers["Access-Control-Allow-Origin"]="*";
		response.body="";
		response.body+=JSON.stringify(output);
		response.end();
	}
	
	
}



